rem -------------  thanks to   -----------------
rem ------  CVirus for the Menu system  --------
rem ---   JSM for the High Score Library  ------
rem -- and of course MOPZ for creating NaaLaa --
rem ------  and sharing it with us -------------
rem ------  visit www.NaaLaa.com  -------------- 
rem --------------------------------------------
rem -----  any questions can be answered on ----
rem --   http://forum.retrogamecoding.org/ -----
rem --------------------------------------------
rem --------------------------------------------
rem ----- sound files from freesound.org -------
rem ------- SOUNDNIMJA KILLKHAN & FINS ---------
rem --------------------------------------------


rem ---------import required libraries----------
rem ============================================


 import "Keycodes.lib"
 import "Speed.lib"
 import "SimpleParticle.lib"
 import "HighScore.lib"

 constant:

WIDTH 640
HEIGHT 480
PLAYER_IMAGE 0
PLAYER_BLOCK_IMAGE 16

FLOOR_IMAGE 1
GOLD_COIN_IMAGE 2
EXPLOSION_IMAGE 3
GHOST_IMAGE 4
KEY_IMAGE 5
GATE_IMAGE 6
HEALTH_IMAGE 7
ARROW_IMAGE 8
TENSEC_IMAGE 9
THIRTYSEC_IMAGE 15
MENU_BG_IMAGE 10
LIFT_BLOCK_IMAGE 11
LIFT_IMAGE 12
JUMP_BOOST_IMAGE 14
LARGE_ARROW_IMAGE 17
PLAYER_DISTORTED_IMAGE 18


COIN_SOUND 0
JUMP_SOUND 1
KEY_SOUND 2
GATE_SOUND 3
JUMP_PLATFORM_SOUND 4
MORE_TIME_SOUND 5
MENU_SOUND 6

GHOST_ALIVE 0
GHOST_X 3
GHOST_Y 2
GHOST_OLD_X 1
GHOST_OLD_Y 5
GHOST_MAX 4
GHOST_DIRECTION 6


LEFT 0
RIGHT 1
UP 2
DOWN 3

GRIDX  20
GRIDY  15

GRID_ELEMENTS 300

 hidden:


set color 0, 0, 0
	cls
	set color 255, 255, 255

rem draw image MENU_BG_IMAGE,0,0
rem 	set caret 320, 100
rem 	center "Loading ..."
rem 	redraw

create font 0,"impact",24,true,false,false,true
save font 0,"impact24.txt","impact24.bmp"


create font 1,"impact",30,true,false,false,true
save font 1,"impact30.txt","impact30.bmp"

create font 2,"impact",48,true,false,false,true
save font 2,"impact48.txt","impact48.bmp"





 load image MENU_BG_IMAGE ,"data/menu_bg.bmp"
 draw image MENU_BG_IMAGE,0,0
 set color 0,0,255
 draw rect 250,230,140,60,true
 set color 255,255,255

	set caret 320, 240
	center "LOADING ..."
	center "Please wait..."
	redraw

load image PLAYER_BLOCK_IMAGE,"data/characterWithBlock.bmp"
set image colorkey PLAYER_BLOCK_IMAGE,255,255,255
set image grid PLAYER_BLOCK_IMAGE,4,4


load image PLAYER_IMAGE,"data/character.bmp"
set image colorkey PLAYER_IMAGE,255,255,255
set image grid PLAYER_IMAGE,4,4

load image FLOOR_IMAGE, "data/wall.bmp"

load image GOLD_COIN_IMAGE, "data/coin_gold.bmp"
set image colorkey GOLD_COIN_IMAGE,0,0,0
set image grid GOLD_COIN_IMAGE,8,1

load image EXPLOSION_IMAGE, "data/fuzz.bmp"
set image grid EXPLOSION_IMAGE, 3, 1

load image GHOST_IMAGE, "data/ghost.bmp"
set image colorkey GHOST_IMAGE,0,0,0

load image KEY_IMAGE, "data/key.bmp"
set image colorkey KEY_IMAGE,0,0,0

load image GATE_IMAGE, "data/gate.bmp"
set image colorkey GATE_IMAGE,0,0,0

load image HEALTH_IMAGE, "data/health.bmp"
set image colorkey HEALTH_IMAGE,0,0,0

load image ARROW_IMAGE, "data/arrow.bmp"
set image colorkey ARROW_IMAGE,0,0,0
set image grid ARROW_IMAGE,2,1

load image TENSEC_IMAGE, "data/10sec.bmp"
set image colorkey TENSEC_IMAGE,0,0,0

load image THIRTYSEC_IMAGE, "data/30sec.bmp"
set image colorkey THIRTYSEC_IMAGE,0,0,0

load image LIFT_BLOCK_IMAGE,"data/lift_block.bmp"
set image colorkey LIFT_BLOCK_IMAGE,0,0,0

load image LIFT_IMAGE,"data/lift_image.bmp"

load image JUMP_BOOST_IMAGE, "data/jump_boost.bmp"
set image colorkey JUMP_BOOST_IMAGE, 0,0,0
set image grid JUMP_BOOST_IMAGE, 2,1

load image LARGE_ARROW_IMAGE, "data/large_arrow.bmp"
set image colorkey LARGE_ARROW_IMAGE, 0,0,0
set image grid LARGE_ARROW_IMAGE, 2,1

load image PLAYER_DISTORTED_IMAGE, "data/character_distorts.bmp"
set image colorkey PLAYER_DISTORTED_IMAGE, 0,0,255
set image grid PLAYER_DISTORTED_IMAGE, 8,2

rem ------------------------------------------------

load sound COIN_SOUND,"data/CoinCollected.wav"
load sound JUMP_SOUND,"data/jump.wav"
load sound KEY_SOUND,"data/CollectKey.wav"
load sound GATE_SOUND,"data/Gate.wav"
load sound JUMP_PLATFORM_SOUND,"data/jump_platform.wav"
load sound MORE_TIME_SOUND,"data/more_time.wav"
load sound MENU_SOUND,"data/menu.wav"

rem ------------------------------------------------

rem create a high score list if necessary
if not HS_Load("hs_list.txt")
	proc HS_Init 10, "Michael", 400
endif


rem =============================


 set window 0, 0, WIDTH, HEIGHT; rem ,true
 set redraw off

visible:
rem initialise variables
rem ---- for level design ---

filename0$ = "levels/level_practice.txt"


filename1$ = "levels/level1.txt"
filename2$ = "levels/level2.txt"
filename3$ = "levels/level3.txt"
filename4$ = "levels/level4.txt"
filename11$ = "levels/level11.txt"
filename12$ = "levels/level12.txt"
filename13$ = "levels/level13.txt"
filename14$ = "levels/level14.txt"

gridplatform[GRID_ELEMENTS]

gridplatform_level_practice[GRID_ELEMENTS]

gridplatform_level1[GRID_ELEMENTS]
gridplatform_level2[GRID_ELEMENTS]
gridplatform_level3[GRID_ELEMENTS]
gridplatform_level4[GRID_ELEMENTS]
gridplatform_level11[GRID_ELEMENTS]
gridplatform_level12[GRID_ELEMENTS]
gridplatform_level13[GRID_ELEMENTS]
gridplatform_level14[GRID_ELEMENTS]


x = 0
y = 0
platform[GRIDX][GRIDY]
count = 0
level = 0
firstrun = true
rem =========================

rem ---- walls  ------------------------------------
wall_startx[GRID_ELEMENTS]
wall_starty[GRID_ELEMENTS]

for a = 0 to GRID_ELEMENTS - 1
	wall_startx[a] = 0
	wall_starty[a] = 0
next

wall_counter = 0
wall_width = 32
wall_height = 32


block_held = false


rem ================================================
rem  ----------   player   -------------------------
PlayerX = 32
PlayerY = 288
rem PlayerW = 30
rem PlayerW is smaller than actual to help with collision detection
PlayerW = 24
PlayerH = 30
PlayerCell = 0
PlayerCellCounter = 0
PlayerRowAdj = 0

PlayerDY = 8

PlayerSpeed = 1
PlayerGravityTimer
PlayerOnGround
PlayerJumping
PlayerJumpTimer
PlayerJumpBoost = 105

rem PlayerJumpHeight = 100/PlayerDY
rem 100 = low jump   120 = high jump
PlayerJumpHeight = PlayerJumpBoost/PlayerDY

PlayerDirection = RIGHT
PlayerOnLift
PlayerOnLiftX
PlayerOnLiftY
CanMove

player_distorts_timer = 0
player_distorts_cell = 0

rem ======================================================
rem -----------------  ghost  ----------------------------
ghosts[GHOST_MAX][16]

ghost_dir[] = [UP,DOWN,LEFT,RIGHT]
ghost_x[]=[450,280,540,140]
ghost_y[]=[100,250,370,120]

for a = 0 to GHOST_MAX - 1
	ghosts[a][GHOST_ALIVE] = true
	ghosts[a][GHOST_X] = ghost_x[a]
	ghosts[a][GHOST_Y] = ghost_y[a]
	ghosts[a][GHOST_OLD_X] = 450
	ghosts[a][GHOST_OLD_Y] = 100
	ghosts[a][GHOST_DIRECTION] = ghost_dir[rnd(4)]
next

ghost_x_inc = 1
ghost_y_inc = 1
ghost_inc = 1

ghost_timer = 0

GhostCanMove = true
rem ======================================================
coin_counter
coin_cell
score = 0
coin_worth = 20
lives = 3
initial_time = 240
time_left = initial_time
time_left_counter = 0
countdown

jump_boost_timer = 0
jump_boost_cell = 0


rem message1$ = "Left mouse-click removes or adds a wall"
message1$ = "Left click removes or adds a wall block"
message2$ = "The Jumping Boost lasts for 30 seconds"
message3$ = "Keep left or right pressed as you jump"

message_displayed$ = message1$ 
rem message_x = - 200 
message_x = 180 
message_y = 452 
message_alpha = 0

name$

key_held = false
 proc SP_Init 200
proc MenuScreen


rem -----------------------------------
rem ------   for practice screen  -----
rem -----------------------------------
large_arrow_timer = 0
large_arrow_cell = 0
arrow_count = 1


 shouldDraw = true

rem ====================================================================================================
rem =====================================   start of game loop   =======================================
rem ====================================================================================================
 do
if level = 0 and keydown("X") then proc MenuScreen
rem ---------------------------------------------------------------------------
rem ---------------------------------------------------------------------------
rem -----------------------   set up timers   ---------------------------------
rem ---------------------------------------------------------------------------
rem ---------------------------------------------------------------------------
PlayerCellCounter = (PlayerCellCounter + 1) % 12
if PlayerCellCounter = 0 then PlayerCell = (PlayerCell + 1 ) % 4
rem proc reset_level
coin_counter = (coin_counter + 1) % 6
if coin_counter = 3 then coin_cell = (coin_cell + 1) % 8


ghost_timer = ghost_timer + 1

time_left_counter =(time_left_counter + 1) % 60
if time_left_counter =50 then time_left =time_left -1


jump_boost_timer = (jump_boost_timer + 1 ) % 40
if jump_boost_timer = 0
	jump_boost_cell = (jump_boost_cell + 1) % 2
endif

rem this limits the time that the boost is available for
if PlayerJumpBoostTimer > 0
	PlayerJumpBoostTimer = PlayerJumpBoostTimer - 1
	PlayerJumpBoost = 150
else
	PlayerJumpBoost = 105
endif



message_alpha = (message_alpha +1) % 255
if message_alpha = 254
	number = (number + 1 ) % 3
	message_displayed$ = str("message"+str(number)+".txt")
endif





large_arrow_timer = (large_arrow_timer + 1) % 20
if large_arrow_timer = 10
	large_arrow_cell = (large_arrow_cell + 1) % 2 
endif


player_distorts_timer = (player_distorts_timer + 1) % 20 
if player_distorts_timer = 19 then player_distorts_cell = (player_distorts_cell + 1) ;rem % 16





rem ---------------------------------------------------------------------------
rem ---------------------------------------------------------------------------
rem ----------------------------   game logic  ------------------------------
rem ---------------------------------------------------------------------------
rem ---------------------------------------------------------------------------
rem ----  set up the walls -----
if firstrun = true
	proc initialise_game_arrays
open file 0, filename1$
	proc reset_level
free file 0
endif
rem ============================
rem check for end of game
if time_left < 1 then proc EndGame


rem ===========================================================================================================
rem player is put 35 pixels into new room
rem to avoid "sticking"
if PlayerX < 0
	old_level = level
	level = level - 1
	rem open file 0, filename1$
	proc reset_level
	PlayerX = 608
		rem this prevents Player getting stuck in locked door -----	
		proc collision
			if CanMove = false
				level = old_level		
				rem level = level + 1
				proc reset_level
				PlayerX = 0
				set caret PlayerX + 96,PlayerY
            center "Gate is locked"
				center "from the other side"
				redraw

			endif
endif




if PlayerX > 608
	old_level = level
	level = level + 1
	proc reset_level
	PlayerX = 16

	rem this prevents Player getting stuck in locked door -----	
		proc collision
			if CanMove = false
				level = old_level		
				rem level = level - 1
				proc reset_level
				PlayerX = 608
				set caret PlayerX - 96,PlayerY
            center "Gate is locked"
				center "from the other side"
				redraw

			endif



endif

if PlayerY < 32
	old_level = level
	level = level - 10
	proc reset_level
	PlayerY = 432

	rem this prevents Player getting stuck in locked door -----	
		proc collision
			if CanMove = false
				level = old_level		
				rem level = level + 10
				proc reset_level
				PlayerY = 32
				set caret PlayerX ,PlayerY + 96
            center "Gate is locked"
				center "from the other side"
				redraw

			endif

endif




if PlayerY > 416
	old_level = level
	level = level + 10
	proc reset_level
	PlayerY = 32
	rem this prevents Player getting stuck in locked door -----	
		proc collision
			if CanMove = false
				level = old_level		
				rem level = level - 10
				proc reset_level
				PlayerY = 416
				set caret PlayerX ,PlayerY - 96
            center "Gate is locked"
				center "from the other side"
				redraw

			endif


endif





rem ----------  player gravity  ------------
PlayerGravityTimer = (PlayerGravityTimer + 1)%3
if PlayerGravityTimer = 0
PlayerY = PlayerY + PlayerDY


proc collision
if not CanMove 
PlayerY = PlayerY - PlayerDY

endif
endif


if not PlayerOnGround 
	if PlayerDirection = LEFT
		PlayerX = PlayerX - 1
	else
		PlayerX = PlayerX + 1
	endif
proc collision
if not CanMove 
	if PlayerDirection = LEFT
		PlayerX = PlayerX + 1
	else
		PlayerX = PlayerX - 1
	endif
endif
endif


rem ---------------------------------------------------------------------------
rem ---------------------------------------------------------------------------
rem --------------------   call procedures   ----------------------------------
rem ---------------------------------------------------------------------------
rem ---------------------------------------------------------------------------
proc drawing
proc controls
proc add_barrier
rem proc collision
proc testground
proc collision_block2
proc ghosts_action
if level = 2 then proc ghost_collision
if lives = 0 or time_left = 0
proc EndGame
endif
rem ---------------------------------------------------------------------------
rem ---------------------------------------------------------------------------
rem   ----------------   set timers   -----------------------------------------
rem ---------------------------------------------------------------------------
rem ---------------------------------------------------------------------------




	 shouldDraw = SPD_HoldFrameDraw(60)
 until keydown(27) or not running()
rem ===================================================================================
rem ===================================================================================
rem ===================================================================================
rem ===================================================================================
rem ===================================================================================
rem ===================================================================================
rem ===================================================================================
rem ===================================================================================
rem ===================================================================================

rem procedures  ------------------------------    procedures   ------

rem ---------------------------------------------------------------
rem ----------------    drawing routines   ------------------------
rem ---------------------------------------------------------------
procedure drawing()
if shouldDraw
	set color 0,0,255
 	cls
 	set color 255,255,255
rem -----------------   draw player  -----------------------------
set color 255,255,255

if block_held = false
	draw image PLAYER_IMAGE, PlayerX, PlayerY,PlayerCell + PlayerRowAdj
else
	draw image PLAYER_BLOCK_IMAGE, PlayerX, PlayerY,PlayerCell + PlayerRowAdj
endif

rem ==============================================================


rem ----    draw the walls   -----
a = 0
b = 0
x = 0
y = 0


for c = 0 to GRID_ELEMENTS - 1
 	if platform[a][b]  = 4
		draw image GATE_IMAGE, x,y
	endif

if platform[a][b]  = 2
rem set color 0,0,0
		draw image GOLD_COIN_IMAGE,x,y,coin_cell
	endif

if platform[a][b]  = 3 
rem set color 0,0,255
		draw image KEY_IMAGE, x,y
	endif
set color 255,255,255




if platform[a][b]  = 1
rem set color 0,255,0
		draw image FLOOR_IMAGE, x,y
	endif

if platform[a][b]  = 5
		draw image HEALTH_IMAGE, x,y
	endif

if platform[a][b]  = 6
		draw image ARROW_IMAGE, x,y,0
	endif

if platform[a][b]  = 10
		draw image TENSEC_IMAGE, x,y
	endif
if platform[a][b]  = 11
		draw image THIRTYSEC_IMAGE, x,y
	endif

if platform[a][b]  = 12
		draw image LIFT_BLOCK_IMAGE, x,y
	endif

if platform[a][b]  = 14
		draw image JUMP_BOOST_IMAGE, x,y,jump_boost_cell
	endif


set color 255,255,255





x = x + wall_width
a = a + 1

	if a = GRIDX
		x = x - (GRIDX * wall_width)
		y = y + wall_height
		a = 0
		b = b + 1
	endif
next

rem -----  particles appear, if triggered
proc SP_DoParticles

rem ===============================

if PlayerOnLift = true
	draw image LIFT_BLOCK_IMAGE, PlayerOnLiftX,PlayerOnLiftY
endif


rem =============================================================
rem -----------------------   draw ghosts  ---------------------------------
if level = 2
for a = 0 to GHOST_MAX - 1	
		if ghosts[a][GHOST_ALIVE] = true
			draw image GHOST_IMAGE,ghosts[a][GHOST_X],ghosts[a][GHOST_Y]
		endif
next
endif
rem ================================================================




rem ------------ show hints at bottom of the screen  --------------------
set color 0,0,0,message_alpha
set caret message_x ,message_y

if number = 0
 center message1
elseif number = 1
 center message2
elseif number = 2
 center message3

endif


set color 255,255,255
rem - shows a block if one has been picked up
if block_held = true
draw image FLOOR_IMAGE,480,448
set caret 576,452
center "BLOCK HELD"
else
set caret 560,452
center "NO BLOCK HELD"

endif


rem message_x = (message_x + 1) % 	(WIDTH - 120)
rem =====================================================================
rem --------------------  show score and health  ------------------------
set color 0,255,0
set caret 50,4
center "Score   ",score

set color 255,255,255
rem -----------------------------------------------------------
if time_left < 10
	set color 255,0,0
else
	set color 0,255,0
endif


if time_left < initial_time - 10 and time_left > 30
	set caret 180,4
	center "Time left  ",time_left 
else
	set font 2
	set color 255,0,0,96
	set caret 190,64
	center "Time left"
	rem center ""
	center time_left 
	set color 255,255,255
endif








set font 0
rem -----------------------------------------------------------

set color 255,255,255
set caret 300,4
center "level  ",level


if lives < 2
	set color 255,0,0
else
	set color 255,255,255
endif



set caret 400,4
center "Lives  ",lives




set color 255,255,255

set caret 540,4
	rem set color 0,128,0,255
	z = HS_GetScore(0)
	center "High Score   ",z
	


if PlayerJumpBoost > 105
	draw image JUMP_BOOST_IMAGE, 416,448,1
endif


if PlayerJumpBoostTimer > 0
set caret 464,452
center int(PlayerJumpBoostTimer / 60)
endif



rem -------------   PRACTICE LEVEL   -------------------
if level = 0


rem for testing - will be removed
if player_distorts_cell < 16
	draw image PLAYER_DISTORTED_IMAGE,0,0 ,player_distorts_cell
endif




if PlayerY > 240 
	set caret 320,70
else
	set caret 320,385
endif
set font 1
center "Press < x > to return to"
center "the main Menu at any time"
set font 0

if PlayerY = 384;rem and arrow_count <> 2

rem	if arrow_chk1 = true
	rem if arrow_count = 1
		draw image LARGE_ARROW_IMAGE, PlayerX - 16,300,large_arrow_cell
		set caret 100,210
		center "Player starts here"
		center "Use arrow keys to "
		center "move - to jump use"
		center "left/right and up"
	rem endif
rem else
rem	arrow_count = 2
endif

if PlayerY = 352 and PlayerX > 160
platform[6][11] = 0

rem PlayerX = 220
rem PlayerY = 320
endif

if PlayerY = 352 
		draw image LARGE_ARROW_IMAGE, 172,278,large_arrow_cell
		set caret 200,178
		center "Touch these arrows"
		center "and you LOSE "
		center "a life"
endif

if PlayerY = 320 
		draw image LARGE_ARROW_IMAGE, 290,246,large_arrow_cell
		set caret 318,146
		center "Collect coins to"
		center "earn points"
		
endif
if PlayerY = 288 
		draw image LARGE_ARROW_IMAGE, 410,214,large_arrow_cell
		set caret 440,124
		center "Collect a key"
		center "to open the gate"
		
endif

if PlayerY = 192 and PlayerX > 320

		draw image LARGE_ARROW_IMAGE, 510,160,large_arrow_cell
		set caret 420,114
		center "You'll need to jump"
		center "from the extreme edge"
		center "to reach the next ledge"
endif


if PlayerY = 160 and PlayerX > 320

		draw image LARGE_ARROW_IMAGE, 394,114,large_arrow_cell
		set caret 250,84
		center "Trapped? You can remove a block"
		
		center "by left clicking on it"
		
		center "...left click on a blank space to replace the block"
		center ""
		center "You can only do this on blocks that are"
		center "close to the Player"
		center ""
		center "Care - if you replace a block on top of the Player"
		center "You will have to remove it again by left clicking"
set color 255,0,0
draw rect 416,128,96,96
set color 255,255,255
endif

if PlayerY = 224 and PlayerX < 320
		draw image LARGE_ARROW_IMAGE, 208 ,160 ,large_arrow_cell
		set caret 240,110
		center "You gain extra"
		center "time with these"
		rem center "to reach the next ledge"
endif

if PlayerY = 256 and PlayerX < 320
		draw image LARGE_ARROW_IMAGE, 32 ,180 ,large_arrow_cell
		set caret 216,250
		center "This lets you jump"
		center "higher for a limited time"
		rem center "to reach the next ledge"
endif

if PlayerY = 128 ;rem and PlayerX < 320
		draw image LARGE_ARROW_IMAGE, 232 ,90 ,large_arrow_cell
		set caret 216,150
		center "This lift will take"
		center "you up one level"
		rem center "to reach the next ledge"
endif



endif



rem for testing >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

set caret 100,20
rem center "mousex()   ",mousex()
rem center "mousey()   ",mousey()
rem center "PlayerDirection = ",PlayerDirection
rem center "PlayerSpeed   ",PlayerSpeed 
rem center "PlayerJumpBoost  ",PlayerJumpBoost 
rem center "number     ",number
rem center "PlayerJumpBoostTimer  ",PlayerJumpBoostTimer 
rem center "arrow_count   ",arrow_count
rem draw rect 640 - 270,480 - 32,370,32
rem draw rect 0,480 - 32,370,32

draw rect 384,448,32,32
draw rect 416,448,64,32
draw rect 480,448,160,32


rem ========================================================================

rem ---- the following is for testing only  ------------------------------------------------
rem set color 255,255,255
rem center "mousex  ",mousex()
rem center "mousey  ",mousey()
rem center "GhostCanMove  ",GhostCanMove
rem set caret 100,80
rem center "PlayerOnGround ",PlayerOnGround 
	 redraw
endif
endproc
rem ============================================================================================
procedure controls()
if time_left < initial_time  / 4 * 2 
	PlayerSpeed = 3
elseif  time_left < initial_time  / 4 * 3
	PlayerSpeed = 2
else
	PlayerSpeed = 1
endif
rem ---------------------------------------------------------------
rem -----  by checking for collision <before> allowing a move  ----
rem ---------  the Player moves much more smoothly ----------------
rem ---------------------------------------------------------------
if PlayerOnGround
	if keydown(37)
		PlayerX = PlayerX - PlayerSpeed
		PlayerDirection = LEFT
		PlayerRowAdj = 8
rem play sound JUMP_PLATFORM_SOUND


	elseif keydown(39)
		PlayerX = PlayerX + PlayerSpeed
		PlayerDirection = RIGHT
		PlayerRowAdj = 12
	else
		PlayerRowAdj = 0

	endif

		proc collision
		if CanMove = false
			if keydown(37)
				PlayerX = PlayerX + PlayerSpeed

			elseif keydown(39)
				PlayerX = PlayerX -  PlayerSpeed
			endif
		endif
endif
endproc
rem =====================================================================
procedure collision()
CanMove = true
for a = 0 to GRID_ELEMENTS - 1
	if PlayerY + PlayerH  > wall_starty[a]
		if PlayerY  < wall_starty[a] + wall_height
			if PlayerX < wall_startx[a]  + wall_width - 2
				if PlayerX + PlayerW > wall_startx[a]
					CanMove = false
				endif
			endif
		endif
	endif
next
rem test for collision with a locked door
a = 0
b = 0
x = 0
y = 0


for c = 0 to GRID_ELEMENTS - 1
if platform[a][b]  = 4
	if PlayerX + PlayerW > a * wall_width
		if PlayerX  < (a+ 1) * wall_width - 2
			if PlayerY + PlayerH > b * wall_height
				if PlayerY < (b+1) * wall_height
					
					if platform[12][14]  <> 3
							CanMove = false
						elseif platform[12][14]  = 3
							play sound GATE_SOUND
							rem CanMove = true
	
							platform[a][b]  = 0
							
							gridplatform[a+(b*GRIDX)] = 0
							
							platform[12][14]  = 0
							gridplatform[292] = 0
						
					 	endif
				endif
			endif
		endif
	endif
endif



x = x + wall_width
a = a + 1

	if a = GRIDX
		x = x - (GRIDX * wall_width)
		y = y + wall_height
		a = 0
		b = b + 1
	endif
next


endproc
rem ===========================================================================================

procedure collision_block2()
rem ================================================================================================================
rem - test for collision with a coin

a = 0
b = 0
x = 0
y = 0


for c = 0 to GRID_ELEMENTS - 1


if platform[a][b]  = 2
	if PlayerX + width(PLAYER_IMAGE) > a * wall_width
		if PlayerX  < (a+ 1) * wall_width
			if PlayerY + height (PLAYER_IMAGE) > b * wall_height
				if PlayerY < (b+1) * wall_height
					platform[a][b]  = 0
					play sound COIN_SOUND

						gridplatform[a+(b*GRIDX)] = 0
						score = score + coin_worth
						proc SP_AddPoof 3, -2, a * wall_width + 16, b * wall_height, 8, 4.0, 2.0, 0.045, false, true

				endif
			endif
		endif
	endif
endif

rem - test for a collision with a key
if platform[a][b]  = 3 and gridplatform[292] <> 3

	if PlayerX + width(PLAYER_IMAGE) > a * wall_width
		if PlayerX  < (a+ 1) * wall_width
			if PlayerY + height (PLAYER_IMAGE) > b * wall_height
				if PlayerY < (b+1) * wall_height
					platform[a][b]  = 0
					rem --  show key at base of screen 
					platform[12][14]  = 3
					play sound KEY_SOUND
					
						gridplatform[a+(b*GRIDX)] = 0
						gridplatform[292] = 3

						proc SP_AddPoof 3, -2, a * wall_width + 16, b * wall_height, 8, 4.0, 2.0, 0.045, false, true
						key_held = true
				endif
			endif
		endif
	endif
endif

rem - test for a collision with a 10 sec bonus
if platform[a][b]  = 10
	if PlayerX + width(PLAYER_IMAGE) > a * wall_width
		if PlayerX  < (a+ 1) * wall_width
			if PlayerY + height (PLAYER_IMAGE) > b * wall_height
				if PlayerY < (b+1) * wall_height
					platform[a][b]  = 0
					gridplatform[a+(b*GRIDX)] = 0
						play sound MORE_TIME_SOUND

							proc SP_AddPoof 3, -2, a * wall_width + 16, b * wall_height, 8, 4.0, 2.0, 0.045, false, true
						time_left = time_left + 10
				endif
			endif
		endif
	endif
endif

rem - test for a collision with a 30 sec bonus
if platform[a][b]  = 11
	if PlayerX + width(PLAYER_IMAGE) > a * wall_width
		if PlayerX  < (a+ 1) * wall_width
			if PlayerY + height (PLAYER_IMAGE) > b * wall_height
				if PlayerY < (b+1) * wall_height
					platform[a][b]  = 0
					gridplatform[a+(b*GRIDX)] = 0
						play sound MORE_TIME_SOUND

						proc SP_AddPoof 3, -2, a * wall_width + 16, b * wall_height, 8, 4.0, 2.0, 0.045, false, true
						time_left = time_left + 30
				endif
			endif
		endif
	endif
endif


rem - test for a collision with an arrow
if platform[a][b]  = 6
	if PlayerX + width(PLAYER_IMAGE) - 10 > a * wall_width
		if PlayerX + 10 < (a+ 1) * wall_width
			if PlayerY + height (PLAYER_IMAGE) - 10 > b * wall_height
				if PlayerY  + 10 < (b+1) * wall_height
					platform[a][b]  = 0
					
						gridplatform[a+(b*GRIDX)] = 0
						
						proc SP_AddPoof 3, -2, a * wall_width + 16, b * wall_height, 8, 4.0, 2.0, 0.045, false, true
						set caret 320,200
					lives = lives - 1


					center "AARGH!"
					center "YOU LOSE A LIFE..."
					center "BACK TO THE START YOU GO...."

proc player_dies



					wait 2000
					
					PlayerX = 32
					PlayerY = 320
					
				endif
			endif
		endif
	endif
endif

rem ===================================================
rem - test for a collision with an jump_boost
if platform[a][b]  = 14
	if PlayerX + width(PLAYER_IMAGE) - 10 > a * wall_width
		if PlayerX + 10 < (a+ 1) * wall_width
			if PlayerY + height (PLAYER_IMAGE) - 10 > b * wall_height
				if PlayerY  + 10 < (b+1) * wall_height
					

play sound JUMP_PLATFORM_SOUND

platform[a][b]  = 0
					
						gridplatform[a+(b*GRIDX)] = 0

PlayerJumpBoost = 150
PlayerJumpBoostTimer = 1800
PlayerJumpHeight = PlayerJumpBoost/PlayerDY

rem proc SP_AddPoof 3, -2, a * wall_width + 16, b * wall_height, 8, 4.0, 2.0, 0.045, false, true




						
		rem				proc SP_AddPoof 3, -2, a * wall_width + 16, b * wall_height, 8, 4.0, 2.0, 0.045, false, true
		rem				set caret 320,200
		rem			lives = lives - 1
		rem			center "AARGH!"
		rem			center "YOU LOSE A LIFE..."
		rem			center "BACK TO THE START YOU GO...."
		rem			redraw
		rem			wait 2000
					
		rem			PlayerX = 32
		rem			PlayerY = 320
					
				endif
			endif
		endif
	endif
endif

rem - test for a collision with a lift block
if platform[a][b]  = 12
	if PlayerX + width(PLAYER_IMAGE)  > a * wall_width
		if PlayerX  < (a+ 1) * wall_width 
			if PlayerY + height (PLAYER_IMAGE) - 24 > b * wall_height
				if PlayerY < (b+1) * wall_height
					PlayerOnLift = true
					PlayerOnLiftX = a * wall_width
					PlayerOnLiftY = b * wall_height
					PlayerX = a * wall_width
					PlayerY = b * wall_height



do
PlayerY = PlayerY - 1
PlayerOnLiftY = 	PlayerY + 4
wait 10
set color 0,0,0
cls
set color 255,255,255

rem draw image PLAYER_IMAGE, PlayerX, PlayerY,PlayerCell + PlayerRowAdj
shouldDraw = true
proc drawing
rem redraw

until PlayerY =  0
PlayerOnLift = false

rem - do NOT reset level if on PRACTICE level

if PlayerY < 32 and level <> 0
	old_level = level
	level = level - 10
	proc reset_level
redraw
	PlayerY = 384
	PlayerX = 64
	rem this prevents Player getting stuck in locked door -----	
		proc collision
			if CanMove = false
				level = old_level		
				
				proc reset_level
				PlayerY = 32
				set caret PlayerX ,PlayerY + 96
            center "Gate is locked"
				center "from the other side"
				redraw
				wait 100
			endif

endif

				endif
			endif
		endif
	endif
endif






x = x + wall_width
a = a + 1

	if a = GRIDX
		x = x - (GRIDX * wall_width)
		y = y + wall_height
		a = 0
		b = b + 1
	endif
next




endproc
rem ====================================================================
procedure player_dies()
player_distorts_cell = 0

for j = 0 to 280
	player_distorts_timer = (player_distorts_timer + 1) % 20 
		if player_distorts_timer = 19 then player_distorts_cell = (player_distorts_cell + 1) ;rem % 16
			draw image PLAYER_DISTORTED_IMAGE,PlayerX,PlayerY,player_distorts_cell
			redraw
next



endproc

rem ====================================================================













rem =====================================================================
procedure testground()
PlayerOnGround = false
	for a = 0 to GRID_ELEMENTS - 1
 		if PlayerY + PlayerH  >= wall_starty[a]
rem			if PlayerY < wall_starty[a] + wall_height
				if PlayerX <= wall_startx[a]  + wall_width
					if PlayerX + PlayerW >= wall_startx[a]
						PlayerOnGround = true
					endif
				endif
rem			endif
	endif
next

if PlayerJumping = false and keydown(38,true)
	if not PlayerJumping then play sound JUMP_SOUND
	PlayerJumpTimer = 0
	PlayerJumping = true
	rem if PlayerJumpTimer = 0 then play sound JUMP_SOUND
endif 

if PlayerJumping = true and PlayerJumpTimer < PlayerJumpHeight
	PlayerJumpTimer = PlayerJumpTimer + 1
	PlayerY = PlayerY - PlayerDY


proc collision
if not CanMove
	PlayerY = PlayerY + PlayerDY

rem if PlayerDirection = RIGHT
rem	PlayerX = PlayerX - 2
rem else
rem	PlayerX = PlayerX + 2
rem endif






	PlayerJumping = false
endif
endif

if PlayerJumpTimer >= PlayerJumpHeight
	PlayerY = PlayerY + PlayerDY

rem if PlayerDirection = RIGHT
rem 	PlayerX = PlayerX - 1
rem else
rem	PlayerX = PlayerX + 1
rem endif



proc collision
if not CanMove
	PlayerY = PlayerY - PlayerDY

rem if PlayerDirection = RIGHT
rem	PlayerX = PlayerX + 2
rem else
rem	PlayerX = PlayerX - 2
rem endif


	PlayerJumping = false
	PlayerJumpTimer = 0
endif
endif



endproc


rem ===========================================
rem =====================================================================================================================
rem ======================================================
procedure reset_level()

rem --- reset PlayerJumpBoost
PlayerJumpBoost = 105
PlayerJumpHeight = PlayerJumpBoost/PlayerDY



for c = 0 to GRID_ELEMENTS - 1
rem for practice screen
if level = 0
		rem this preserves the array ready for when Player returns
			gridplatform[c] = gridplatform_level_practice[c]
endif



	if level = 1 and firstrun = true
		rem this preserves the array ready for when Player returns
			gridplatform[c] = gridplatform_level1[c]
	elseif level = 1 and old_level = 2
			gridplatform_level2[c] = gridplatform[c] 
			gridplatform[c] = gridplatform_level1[c]
	elseif level = 1 and old_level = 11
			gridplatform_level11[c] = gridplatform[c] 
			gridplatform[c] = gridplatform_level1[c]



	elseif level = 2
			rem this preserves the array ready for when Player returns
			if level = 2 and old_level = 3
				gridplatform_level3[c] = gridplatform[c] 
			elseif level = 2 and old_level = 1
				gridplatform_level1[c] = gridplatform[c] 
			endif
				gridplatform[c] = gridplatform_level2[c]

	elseif level = 3
		rem this preserves the array ready for when Player returns
		if level = 3 and old_level = 4
			gridplatform_level4[c] = gridplatform[c] 
		elseif level = 3 and old_level = 2
			gridplatform_level2[c] = gridplatform[c]
		endif
			gridplatform[c] = gridplatform_level3[c]


	elseif level = 4

		if old_level = 14
			gridplatform_level14[c] = gridplatform[c] 
		elseif old_level = 3
			gridplatform_level3[c] = gridplatform[c]
		endif

			gridplatform[c] = gridplatform_level4[c]



	elseif level = 11
		rem this preserves the array ready for when Player returns
		if old_level = 1
			gridplatform_level1[c] = gridplatform[c] 
		endif
			gridplatform[c] = gridplatform_level11[c]

	elseif level = 12
		rem this preserves the array ready for when Player returns
		if old_level = 11
			gridplatform_level11[c] = gridplatform[c] 
		elseif old_level = 13
			gridplatform_level13[c] = gridplatform[c] 
		endif
			gridplatform[c] = gridplatform_level12[c]

	elseif level = 13
		rem this preserves the array ready for when Player returns
		if old_level = 12
			gridplatform_level12[c] = gridplatform[c] 
		elseif old_level = 14
			gridplatform_level14[c] = gridplatform[c] 
		endif
			gridplatform[c] = gridplatform_level13[c]


	elseif level = 14
		rem this preserves the array ready for when Player returns
		if old_level = 4
			gridplatform_level4[c] = gridplatform[c] 
		elseif old_level = 13
			gridplatform_level13[c] = gridplatform[c] 

		endif
			gridplatform[c] = gridplatform_level14[c]


	
	endif


next



d = 0
e = 0

for c = 0 to GRID_ELEMENTS - 1
	platform[d][e] = gridplatform[c]
	d = d + 1
 		if d > GRIDX - 1 
			d = 0
			e = e + 1
		endif 
next
endif


d = 0
e = 0
rem ------   set up 2 arrays   ----------
for c = 0 to GRID_ELEMENTS - 1
rem reset 2 arrays to ensure that they are clear before recalculating wall positions
wall_startx[c] = 0
wall_starty[c] = 0

if platform[d][e] = 1
		wall_startx[c] = d * wall_width
		wall_starty[c] = e * wall_height
endif
			d = d + 1
	if d > GRIDX - 1 
		d = 0
		e = e + 1
	endif 
next
firstrun = false

endproc
rem -=======================================================


procedure initialise_game_arrays()
open file 0, filename1$
open file 1, filename2$
open file 2, filename3$
open file 3, filename4$
open file 4, filename11$
open file 5, filename12$
open file 6, filename13$
open file 7, filename14$

open file 8, filename0$

	
for a = 0 to GRID_ELEMENTS - 1
	gridplatform_level1[a] = read(0)
	gridplatform_level2[a] = read(1)
	gridplatform_level3[a] = read(2)
	gridplatform_level4[a] = read(3)
	gridplatform_level11[a] = read(4)
	gridplatform_level12[a] = read(5)
	gridplatform_level13[a] = read(6)
	gridplatform_level14[a] = read(7)

	gridplatform_level_practice[a] = read(8)

next

free file 0
free file 1
free file 2
free file 3
free file 4
free file 5
free file 6
free file 7
free file 8

endproc
rem ==========================================================
procedure add_barrier()

if time_left > 0






if mousebutton(0,true)
	x = mousex()
	y = mousey()

a = int(x/wall_width)
b = int(y/wall_height)


if a > 0 
if a < 19 
if b > 1 
if b < 13


if platform[a][b]  = 1 and block_held = false

	if PlayerX  >= a * 32
		if PlayerX < (a * 32) + 48; rem - 32
			if PlayerY > (b * 32) - 48 and PlayerY <= (b * 32) + 32
				platform[a][b]  = 0
				gridplatform[a+(b*GRIDX)] = 0
				rem time_left = time_left - 10
				block_held = true
			endif
		endif
	else 
		if PlayerX > (a * 32) - 64
			if PlayerY > (b * 32) - 48 and PlayerY <= (b * 32) + 32
				platform[a][b]  = 0
				gridplatform[a+(b*GRIDX)] = 0
				rem time_left = time_left - 10
				block_held = true
			endif
		endif
	endif

elseif platform[a][b]  = 0 and block_held = true

	if PlayerX  >= a * 32
		if PlayerX < (a * 32) + 48; rem - 32
			if PlayerY > (b * 32) - 48 and PlayerY <= (b * 32) + 32
				platform[a][b]  = 1
				gridplatform[a+(b*GRIDX)] = 1
				rem time_left = time_left - 10
				block_held = false
			endif
		endif
	else 
		if PlayerX > (a * 32) - 64
			if PlayerY > (b * 32) - 48 and PlayerY <= (b * 32) + 32

				platform[a][b]  = 1
				gridplatform[a+(b*GRIDX)] = 1
				rem time_left = time_left - 10
				block_held = false
			endif
		endif
	endif

endif


endif
endif
endif
endif

proc rebuild_wall_arrays
endif
endif
endproc

rem ==========================================
procedure rebuild_wall_arrays()

rem ========  rebuild wall arrays  ===========
rem ==========================================
d = 0
e = 0

for c = 0 to GRID_ELEMENTS - 1
	platform[d][e] = gridplatform[c]
	d = d + 1
 		if d > GRIDX - 1 
			d = 0
			e = e + 1
		endif 
next

d = 0
e = 0
rem ------   set up 2 arrays   ----------
for c = 0 to GRID_ELEMENTS - 1
rem reset 2 arrays to ensure that they are clear before recalculating wall positions
wall_startx[c] = 0
wall_starty[c] = 0

if platform[d][e] = 1
		wall_startx[c] = d * wall_width
		wall_starty[c] = e * wall_height
endif
			d = d + 1
	if d > GRIDX - 1 
		d = 0
		e = e + 1
	endif 
next

endproc

rem ==================================================================

procedure ghosts_action()
randomize time()
rem 450 100 ghost can appear
if level = 2
for a = 0 to GHOST_MAX - 1	

if ghosts[a][GHOST_DIRECTION] = LEFT
	ghost_x_inc = - ghost_inc
elseif ghosts[a][GHOST_DIRECTION] = RIGHT
	ghost_x_inc = ghost_inc
elseif ghosts[a][GHOST_DIRECTION] = UP
	ghost_y_inc = - ghost_inc
elseif ghosts[a][GHOST_DIRECTION] = DOWN
	ghost_y_inc = ghost_inc
endif


ghosts[a][GHOST_OLD_X] = ghosts[a][GHOST_X]
ghosts[a][GHOST_OLD_Y] = ghosts[a][GHOST_Y]

ghosts[a][GHOST_ALIVE] = true
ghosts[a][GHOST_X] = ghosts[a][GHOST_X] + (ghost_x_inc * rnd(2))
ghosts[a][GHOST_Y] = ghosts[a][GHOST_Y] + (ghost_y_inc * rnd(2))


rem proc ghost_collision
for b = 0 to GRID_ELEMENTS - 1
	if ghosts[a][GHOST_Y] + height(GHOST_IMAGE)  > wall_starty[b]
		if ghosts[a][GHOST_Y] < wall_starty[b] + wall_height
			if ghosts[a][GHOST_X] < wall_startx[b]  + wall_width
				if ghosts[a][GHOST_X] + width(GHOST_IMAGE) > wall_startx[b]
					ghosts[a][GHOST_X] = ghosts[a][GHOST_OLD_X]
					ghosts[a][GHOST_Y] = ghosts[a][GHOST_OLD_Y]
					ghosts[a][GHOST_DIRECTION] = ghost_dir[rnd(4)]
				endif
			endif
		endif
	endif
rem ---- keep ghost on screen ------
	if ghosts[a][GHOST_X] < 0 or ghosts[a][GHOST_X] > 640 - width(GHOST_IMAGE)
		ghosts[a][GHOST_X] = ghosts[a][GHOST_OLD_X]
		ghosts[a][GHOST_Y] = ghosts[a][GHOST_OLD_Y]
		ghosts[a][GHOST_DIRECTION] = ghost_dir[rnd(4)]
	endif


next

next



endif


endproc
rem ===============================================================
procedure ghost_collision()
rem -----------------  this is now in the ghost_action proc -----
rem ------ but may be useful late for Player collision  ---------
rem -------------------------------------------------------------
for b = 0 to GHOST_MAX - 1	
	if ghosts[b][GHOST_Y] + height(GHOST_IMAGE) - 8 > PlayerY
		if ghosts[b][GHOST_Y] + 8 < PlayerY + height (PLAYER_IMAGE)
			if ghosts[b][GHOST_X] + 8 < PlayerX  + width (PLAYER_IMAGE)
				if ghosts[b][GHOST_X] + width(GHOST_IMAGE) - 8 > PlayerX 
					rem PlayerHealth = PlayerHealth - 20
					lives = lives - 1
					countdown = 100
					proc player_dies
			
					
			do
					set caret 320,200
					center "GOTCHA!"
					center "YOU WERE TOUCHED BY A GHOST..."
					center "LOSE A LIFE AND BACK TO THE START YOU GO...."

					rem center countdown
					
					draw rect 0,448,640,32
					draw rect 0,448,640 - int(float(countdown) * 6.4),32,true
					redraw
					countdown = countdown - 1
					wait 15
			until countdown = 0

					





					
					PlayerX = 32
					PlayerY = 320
					
				endif
			endif
		endif
	endif
next



endproc
rem --------------------------------------------------
procedure EndGame()

set color 0,0,0

cls

set caret 320,240
set color 255,255,255

if lives = 0
	center "You've run out of lives!"
elseif time_left < 1
	center "Time has run out - end of game"
endif
redraw
wait 2000

proc high_score




rem PlayerHealth = 100
lives = 3
PlayerX = 32
PlayerY = 320
score = 0
time_left = initial_time
key_held = false


proc initialise_game_arrays
open file 0, filename1$
	proc reset_level
free file 0

proc MenuScreen





endproc

rem ============================================================
rem -------------------------------------------------
procedure high_score()

rem check to see if High score qualifies for table
didQualify = HS_IsQualified(score)

set caret 320,0
center "YOUR SCORE: ",score
if didQualify
	proc get_name
endif

if HS_AddEntry(name, score)
						set color 0,0,128
						cls
						set color 255,255,255	
						set caret 320,110

		
		center "Congratulations........... "
		center " you qualified as one of"
		center " the highest scorers..."
else
						set color 0,0,128
						cls
						set color 255,255,255	
						set caret 320,110

		center "Sorry, you did not qualify for "
		center "the high score list......."
endif
redraw

set color 0, 0, 128
cls
set color 255, 255, 255

set caret 320,20
center "YOUR SCORE: ",score
set caret 185, 80
center "Name"
set caret 420, 80
set justification right
write "Score"

	for i = 0 to 9
		
		set caret 170, i*24 + 140
		set justification left
		write HS_GetName(i)

		
		set caret 415, i*24 + 140
		set justification right
		write HS_GetScore(i)
	next

redraw
	wait 4000

if not HS_Save("hs_list.txt")
	rem could not save list for some reason.
endif

endproc

rem -----------------------------------------------------
procedure get_name()

rem Clear screen and display list.
	set color 0, 0, 128
	cls
	set color 255, 255, 255
	
	rem Get name.
set caret 320,0
center "YOUR SCORE: ",score

set redraw on
	set caret 320, 40
	center
	center "Well done - you are one"
	center "of the top 10 scorers"
	center "Enter your name below.."
	center ""
	name$ = rln$(10)
	
set redraw off

endproc



rem ==================================================================================================
rem ==================================================================================================
rem ==================================================================================================
rem ==================================================================================================
rem ==================================================================================================
rem ==================================================================================================
rem ==================================================================================================
rem ==================================   menu   ======================================================
rem ==================================================================================================
rem ==================================================================================================
rem ==================================================================================================
rem ==================================================================================================
rem ==================================================================================================
rem ==================================================================================================
rem ==================================================================================================
rem ==================================================================================================
rem ==================================================================================================
rem ==================================================================================================

procedure MenuScreen()

rem ---- reset all variables so that the option to "Start Game" will work ....
rem ---- ....if not, that option will just trigger the EndGame menu again ..
level = 1
time_left = initial_time
lives = 3
firstrun = true
jump_boost_timer = 0
PlayerJumpBoost = 105

do
menuItem = 0
do
if keydown(VK_DOWN,true) and menuItem < 5 then menuItem = menuItem + 1
if keydown(VK_UP,true) and menuItem > 0 then menuItem = menuItem - 1
set color 0,0,0
cls
set color 255,255,255,64

draw image MENU_BG_IMAGE,0,0




rem draw image FBCK,0,0
rem draw image BANNER, 320 - width(BANNER)/2,50
set caret 320, 170
set color 0,255,255
center "Use Keys To Move in The Menu"
center "Press Space to Select an Item"
set caret 320, 240
rem --------- 
rem -----------------------  start of menu display   ---------------------------------
rem ---------

if menuItem = 0; set color 0,255,255; else; set color 0,96,128;
endif
center "START THE FULL GAME"
rem --------- 

if menuItem = 1; set color 0,255,255; else; set color 0,96,128;
endif
center "HOW TO PLAY"
rem --------- 
if menuItem = 2; set color 0,255,255; else; set color 0,96,128;
level=0
PlayerY = 384
endif
center "PRACTICE LEVEL"

rem --------- 

if menuItem = 3; set color 0,255,255; else; set color 0,96,128;
endif
center "SEE THE HIGH SCORES"


rem --------------
if menuItem = 4; set color 0,255,255; else; set color 0,96,128;
endif
center"QUIT"


rem --------- 
if menuItem = 0; set color 0,255,255; else; set color 0,96,128;
endif
redraw
wait 10
until keydown(VK_SPACE,true)

if menuItem = 1
play sound MENU_SOUND
set color 0,0,0
cls
set color 255,0,255
set caret 320,100
center "The aim of the game is simple - get"
center "as many points as possible before"
center "your lives or the time runs out"
center
set color 0,255,255
center "Points are awarded for collecting coins"
center "and look out for bonus time areas"
center
center "Avoid ghosts and arrows.....deadly!"
center
center "Move with the cursor keys and add"
center "or remove walls by clicking the mouse"
center
set color 255,255,255
center "Press any key to continue..."
redraw
wait keydown
rem if keydown(VK_SPACE)
	set color 0,0,0
	cls
	set color 255,0,255
	set caret 320,50
	center "SYMBOLS"



set color 255,255,255


	
	draw image GOLD_COIN_IMAGE ,70,100,4
	set caret 220,100
	center "Gain 20 Points"


	draw image ARROW_IMAGE ,70,150,0
	set caret 220,150
	center "Lose a life"

	
	draw image GHOST_IMAGE ,70,200,0
	set caret 220,200
	center "Lose a life"

	draw image KEY_IMAGE ,70,250,0
	set caret 220,250
	center "To unlock the Gate"

	draw image JUMP_BOOST_IMAGE ,200,300,1
	set caret 350,300
	rem center "25 sec boost when jumping"
	center "Jump higher for 25 sec"



	
	draw image GATE_IMAGE ,330,100,0
	set caret 480,100
	center "You need the key for this"

	draw image TENSEC_IMAGE ,330,150,4
	set caret 480,150
	center "Get 10 more seconds"


	draw image THIRTYSEC_IMAGE ,330,200,0
	set caret 480,200
	center "Get 30 more seconds"

	
	draw image LIFT_BLOCK_IMAGE ,330,250,0
	set caret 480,250
	center "A lift to one level up"

	set caret 320,350
	center "Hint 1 - pick up or drop blocks close to you with a left click"
	center ".... not the edge ones though - they won't move!"
	center "Hint 2 - keep left or right buttons pressed when jumping......"
 



	set caret 320,400
	center
	set color 255,0,255
	center "Press any key to continue..."
	redraw
	set color 255,255,255

 
rem  14



wait keydown

rem ------------------------
elseif menuItem = 0

rem reset all variables - needed if accessed AFTER practice level
play sound MENU_SOUND
PlayerX = 32
PlayerY = 288
block_held = false
PlayerJumpBoostTimer = 0
PlayerJumpBoost = 105

score = 0
level = 1
time_left = initial_time
lives = 3
firstrun = true
donotreturn = true
rem ------------------------

elseif menuItem = 3
play sound MENU_SOUND

set color 0, 0, 128
cls
set color 255, 255, 255

set caret 160,0
set caret 185, 10
center "Name"
set caret 420, 10
set justification right
write "Score"

	for i = 0 to 9

		set caret 170, i*24 + 40
		set justification left
		write HS_GetName(i)

		set caret 415, i*24 + 40
		set justification right
		write HS_GetScore(i)
	next

set caret 320,400

center "Press any key to continue..."
redraw
wait keydown

elseif menuItem = 2

play sound MENU_SOUND
level = 0

donotreturn = true
rem ------------
elseif menuItem = 4
play sound MENU_SOUND

end

endif
until menuItem = 0 or menuItem = 2

endproc
